package io.jpress.addon.securityinformation.service.provider;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.tx.Tx;
import io.jboot.aop.annotation.Bean;
import io.jpress.addon.securityinformation.model.JpressAddonSecurityinformationSrdDeviceIdentification;
import io.jpress.addon.securityinformation.service.JpressAddonSecurityinformationSrdDeviceIdentificationService;
import io.jpress.addon.securityinformation.service.JpressAddonSecurityinformationSrdService;
import io.jpress.addon.securityinformation.model.JpressAddonSecurityinformationSrd;
import io.jboot.service.JbootServiceBase;

import java.util.List;

@Bean
public class JpressAddonSecurityinformationSrdServiceProvider extends JbootServiceBase<JpressAddonSecurityinformationSrd> implements JpressAddonSecurityinformationSrdService {

    @Inject
    private JpressAddonSecurityinformationSrdDeviceIdentificationService servicedi;

    @Before(Tx.class)
    public void saveSRD(JpressAddonSecurityinformationSrd srd,
                        List<JpressAddonSecurityinformationSrdDeviceIdentification> srddi) {
        Object srdid = save(srd);

        for(JpressAddonSecurityinformationSrdDeviceIdentification srddif : srddi){
            srddif.setSrdId(Long.valueOf(srdid.toString()));
            servicedi.save(srddif);
        }
    }
}
